package mqq.view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;

import javax.swing.JPanel;

import mqq.model.DecisionLinesEvent;
import mqq.model.Edge;

/**
 * GUI panel where the user draws edges
 * @author mqq
 */
public class DrawingPanel extends JPanel {
	/** Entity object associated */
	DecisionLinesEvent event;
	
	public DrawingPanel(DecisionLinesEvent e) {
		this.event = e;
		this.initialize();
	}
	
	/**
	 * Calls the paintComponent() method to initialize
	 */
	void initialize() {
		this.repaint();
	}
	
	/**
	 * Draws lines and edges
	 */
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
		int numLines = this.event.getNumLines();
        for (int i = 0; i < numLines; i++) {
        	int width = 480 / (numLines - 1);
			int x = 60 + i * width;
	        g2.draw(new Line2D.Double(x, 0, x, 340));
	        int numEdges = event.lines.get(i).edges.size();
	        for (int j = 0; j < numEdges; j++) {
	        	Edge e = event.lines.get(i).edges.get(j);
	        	g2.draw(new Line2D.Double(60 + e.getLeft() * width, e.getHeight(), 
	        			60 + e.getRight() * width, e.getHeight()));
	        }
		}
        g2.setPaint(Color.BLACK);
    }
}
